package com.xjc.infra.util.security;

import java.io.UnsupportedEncodingException;

import org.apache.commons.codec.binary.Base64;




public class Security {

	public static String KEY = "J2F45D@Z90~23U5-7O9P1&3L56*89Y)A";
	public static String KEY1 = "J2K45D@Z90~23Z5-7O9P1&3L56*89Y)T";
	public static byte[] encrypt(byte[] data) throws Exception {
	    return SecurityFactory.getEncryptInstance().encrypt(data);
	}
	
	public static byte[] encrypt(byte[] data,String key) throws Exception {
	    return SecurityFactory.getEncryptInstance().encrypt(data,key);
	}
	
	
	public static byte[] encrypt(byte[] data, String key,String type) throws Exception {
	    ISecurity security = SecurityFactory.getEncryptInstance();
	    if(security!=null){
	        return security.encrypt(data);
	    }
	    return null;
	}

	public static byte[] desEncrypt(byte[] data) throws Exception {
	    return SecurityFactory.getEncryptInstance().desEncrypt(data);
	}
	
	public static byte[] desEncrypt(byte[] data, String key) throws Exception {
	    return SecurityFactory.getEncryptInstance().desEncrypt(data,key);
	}
	
	public static byte[] desEncrypt(byte[] data, String key,String type) throws Exception {
	    ISecurity security =SecurityFactory.getEncryptInstance();
	    if(security !=null){
	        return security.desEncrypt(data);
	    }else{
	        return null;
	    }
	}
	
	public static void main(String[] args) throws UnsupportedEncodingException, Exception {
		String str = "我是一个兵，来自老百姓";
		AESSecurity aESSecurity = new AESSecurity();
		String encryStr = Base64.encodeBase64String(aESSecurity.encrypt(str.getBytes()));
		String mw = new String(aESSecurity.desEncrypt(Base64.decodeBase64(encryStr)));
//		byte[] encryStr = aESSecurity.encrypt(str.getBytes(encoding));
//		String mw = new String(aESSecurity.desEncrypt(encryStr));
		System.out.println(mw);
	}
}
